package com.lyj.stuelasticsearch.entity;

import com.lyj.stuelasticsearch.repository.ProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * 测试数据初始化
 */
@Component
public class DataInitializer implements CommandLineRunner {

    @Autowired
    private ProductRepository productRepository;

    @Override
    public void run(String... args) throws Exception {
//
//        // 清空索引
//        productRepository.deleteAll();
//
//        // 初始化测试数据
//        Product p1 = new Product("1", "小米手机", 2999.00, "手机", "小米旗舰手机", 100);
//        Product p2 = new Product("2", "华为笔记本", 5999.00, "电脑", "华为MateBook", 50);
//        Product p3 = new Product("3", "苹果耳机", 1299.00, "耳机", "AirPods Pro", 200);
//        Product p4 = new Product("4", "小米电视", 3999.00, "电视", "小米4K智能电视", 80);
//        Product p5 = new Product("5", "华为手机", 4999.00, "手机", "华为P50 Pro", 150);
//
//        productRepository.saveAll(Arrays.asList(p1, p2, p3, p4, p5));

    }
}